home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
examples
/
libpod
/
lstatus.c.z
/
lstatus.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
8KB
|
289 lines
/**************************************************************************
*
* Copyright (c) 1992 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: lstatus.c
*
* Description: Sample program that demonstrates the use of the local
* form of the libpod status read and write functions.
*
* Usage: lstatus printer_name [op_status]
*
* If op_status is specified, an attempt is made to write the
* new operational status to the printer POD status file. The
* status before and after the write are displayed.
*
* If op_status is not specified, the current status is displayed.
*
* Note: You must have root or lp permissions to successfully run
* this program to write the status file. There is no such
* restriction on reading the status file.
*
**************************************************************************/
#ident "$Revision: 1.4 $"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <pod.h>
#define HANDLE_ERROR(pname) { \
PDPerror(pname); \
exit(1); \
}
void usage(char*);
void disp_opstatus(int);
void disp_status(PDStatusStruct*, PDMessageStruct*);
void disp_colorspace(int);
void disp_depth(int);
void disp_format(int);
int main(int argc, char **argv)
{
int opstatus;
PDStatusStruct *status;
PDMessageStruct *messages;
time_t mod_time;
/*
* Get the printer name from command line
*/
if (argc < 2) {
usage(argv[0]);
exit(1);
}
/*
* Handle status change request
*/
if (argc == 3) {
/*
* Read and display original operational status
*/
if (PDLocalReadOpStatus(argv[1], &opstatus, &mod_time) < 0)
HANDLE_ERROR(argv[0]);
(void)printf("Original status summary - last modified %s\n",
ctime(&mod_time));
disp_opstatus(opstatus);
(void)printf("\n");
/*
* Read and display the original full status and message information
*/
if (PDLocalReadStatus(argv[1], &status, &messages, &mod_time) < 0)
HANDLE_ERROR(argv[0]);
(void)printf("Original complete status - last modified %s\n",
ctime(&mod_time));
disp_status(status, messages);
(void)printf("\n");
/*
* Now attempt to set a new status
*/
(void)printf("Attempting to set operational status to: %s\n\n",
argv[2]);
if (!strcasecmp(argv[2], "busy"))
status->operational_status = PD_STATUS_BUSY;
else if (!strcasecmp(argv[2], "idle"))
status->operational_status = PD_STATUS_IDLE;
else if (!strcasecmp(argv[2], "faulted"))
status->operational_status = PD_STATUS_FAULTED;
else if (!strcasecmp(argv[2], "unavailable"))
status->operational_status = PD_STATUS_UNAVAILABLE;
else {
(void)fprintf(stderr, "Unknown status '%s' specified\n", argv[2]);
status->operational_status = -1;
}
if (status->operational_status >= 0)
if (PDLocalWriteStatus(argv[1], status, messages) < 0)
HANDLE_ERROR(argv[0]);
}
/*
* Read and display only operational status
*/
if (PDLocalReadOpStatus(argv[1], &opstatus, &mod_time) < 0)
HANDLE_ERROR(argv[0]);
(void)printf("Current status summary - last modified %s\n",
ctime(&mod_time));
disp_opstatus(opstatus);
(void)printf("\n");
/*
* Read and display the full status and message information
*/
if (PDLocalReadStatus(argv[1], &status, &messages, &mod_time) < 0)
HANDLE_ERROR(argv[0]);
(void)printf("Current complete status - last modified %s\n",
ctime(&mod_time));
disp_status(status, messages);
return 0;
}
void usage(char *progname)
{
(void)fprintf(stderr, "Usage: %s printer_name ", progname);
(void)fprintf(stderr, "[busy | idle | faulted | unavailable]\n");
}
void disp_opstatus(int status)
{
(void)printf("\tOperational status: ");
switch(status) {
case PD_STATUS_IDLE:
(void)printf("IDLE");
break;
case PD_STATUS_BUSY:
(void)printf("BUSY");
break;
case PD_STATUS_FAULTED:
(void)printf("FAULTED");
break;
case PD_STATUS_UNAVAILABLE:
(void)printf("UNAVAILABLE");
break;
default:
(void)printf("UNKNOWN");
break;
}
(void)printf("\n");
}
void disp_status(PDStatusStruct *status, PDMessageStruct *messages)
{
register int i;
char *options;
disp_opstatus(status->operational_status);
(void)printf("\tMedia type code: %d\n", status->media_type);
(void)printf("\tNumber of colors code: 0x%08X\n",
status->number_of_colors);
(void)printf("\t\tNumber of colors: %d\n",
PD_GET_NUMCOLORS(status->number_of_colors));
disp_colorspace(PD_GET_COLORSPACE_CODE(status->number_of_colors));
disp_depth(PD_GET_DEPTH_CODE(status->number_of_colors));
disp_format(PD_GET_FORMAT_CODE(status->number_of_colors));
(void)printf("\tMedia size code: 0x%08X\n", status->media_size);
(void)printf("\tMedia size name: %s\n",
PDGetNameBySizeCode(status->media_size));
options = status->printer_options;
(void)printf("\tInstalled options: %s\n",
(options && *options != '\0') ? options: "None");
(void)printf("\tMedia size validation mask: %d\n", status->validation_mask);
(void)printf("\tNumber of messages: %d\n", status->error_count);
for (i = 0; i < status->error_count; i++) {
(void)printf("\n\t\tMessage %d code: 0x%08X\n", i+1,
messages[i].message_code);
(void)printf("\t\tMessage %d text: %s\n", i+1,
messages[i].message_text);
}
}
void disp_colorspace(int cspace)
{
(void)printf("\t\tColorspace: ");
switch(cspace) {
case PD_DATA_K:
(void)printf("k\n");
break;
case PD_DATA_CMY:
(void)printf("cmy\n");
break;
case PD_DATA_CMYK:
(void)printf("cmyk\n");
break;
case PD_DATA_W:
(void)printf("w\n");
break;
case PD_DATA_RGB:
(void)printf("rgb\n");
break;
case PD_DATA_YMC:
(void)printf("ymc\n");
break;
case PD_DATA_YMCK:
(void)printf("ymck\n");
break;
case PD_DATA_KCMY:
(void)printf("kcmy\n");
break;
default:
(void)printf("0x%08X\n", cspace);
break;
}
}
void disp_depth(int depth)
{
(void)printf("\t\tDepth: ");
switch(depth) {
case PD_DATA_DEPTH1:
(void)printf("1 bpp\n");
break;
case PD_DATA_DEPTH4:
(void)printf("4 bpp\n");
break;
case PD_DATA_DEPTH8:
(void)printf("8 bpp\n");
break;
default:
(void)printf("0x%08X\n", depth);
break;
}
}
void disp_format(int format)
{
(void)printf("\t\tFormat: ");
switch(format) {
case PD_DATA_CHUNKY:
(void)printf("chunky\n");
break;
case PD_DATA_BANDED:
(void)printf("banded\n");
break;
case PD_DATA_PLANAR:
(void)printf("planar\n");
break;
default:
(void)printf("0x%08X\n", format);
break;
}
}